package cn.yhjz.platform.system.service.impl;

import cn.yhjz.common.Pager;
import cn.yhjz.platform.system.entity.SysDept;
import cn.yhjz.platform.system.vo.SysDeptVo;
import cn.yhjz.platform.system.mapper.SysDeptMapper;
import cn.yhjz.platform.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = {Exception.class})
public class SysDeptServiceImpl implements ISysDeptService {

    @Autowired
    private SysDeptMapper sysDeptMapper;


    @Override
    public Pager getPage(Long currentPage, Long pageSize, SysDept sysDept) {
        Pager pager = new Pager();
        Long count = sysDeptMapper.getPageCount(sysDept);
        Long pageOffset = (currentPage - 1) * pageSize;
        List<SysDeptVo> records = sysDeptMapper.getPage(pageOffset, pageSize, sysDept);
        pager.setRows(records);
        pager.setCurrentPage(currentPage);
        pager.setPageSize(pageSize);
        pager.setTotalPageCount(count);
        return pager;
    }

    @Override
    public SysDept insert(SysDept sysDept) {
        int res = sysDeptMapper.insert(sysDept);
        if (res > 0) {
            return sysDept;
        } else {
            return null;
        }
    }

    @Override
    public List<SysDeptVo> select(SysDept sysDept) {
        return sysDeptMapper.select(sysDept);
    }

    @Override
    public SysDeptVo selectById(Long id) {
        return sysDeptMapper.selectById(id);
    }

    @Override
    public int deleteById(Long id) {
        return sysDeptMapper.deleteById(id);
    }

    @Override
    public int updateByIdWithNull(SysDept sysDept) {
        return sysDeptMapper.updateByIdWithNull(sysDept);
    }

    @Override
    public int updateById(SysDept sysDept) {
        return sysDeptMapper.updateById(sysDept);
    }

    @Override
    public int update(SysDept entity, SysDept param) {
        return sysDeptMapper.update(entity, param);
    }

    @Override
    public int updateWithNull(SysDept entity, SysDept param) {
        return sysDeptMapper.updateWithNull(entity, param);
    }
}
